﻿
namespace ATA.Windows.Forms
{
	/// <summary>
	/// abstract DieuKienGiamGia typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DieuKienGiamGiaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DieuKienGiamGiaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DieuKienGiamGia _currentDieuKienGiamGia = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDieuKienGiamGiaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDieuKienGiamGiaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDieuKienGiamGiaBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the DieuKienId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDieuKienIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DieuKienChung property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDieuKienChungDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the LastUpdate property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxLastUpdateDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the UpdateBy property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxUpdateByDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IsActive property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxIsActiveDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DieuKienGiamGia> _DieuKienGiamGiaList;
				
		/// <summary> 
		/// The list of DieuKienGiamGia to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DieuKienGiamGia> DieuKienGiamGiaList
		{
			get {return this._DieuKienGiamGiaList;}
			set
			{
				this._DieuKienGiamGiaList = value;
				this.uxDieuKienGiamGiaBindingSource.DataSource = null;
				this.uxDieuKienGiamGiaBindingSource.DataSource = value;
				this.uxDieuKienGiamGiaDataGridView.DataSource = null;
				this.uxDieuKienGiamGiaDataGridView.DataSource = this.uxDieuKienGiamGiaBindingSource;				
				//this.uxDieuKienGiamGiaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDieuKienGiamGiaBindingSource_ListChanged);
				this.uxDieuKienGiamGiaBindingSource.CurrentItemChanged += new System.EventHandler(OnDieuKienGiamGiaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDieuKienGiamGiaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDieuKienGiamGia = uxDieuKienGiamGiaBindingSource.Current as Entities.DieuKienGiamGia;
			
			if (_currentDieuKienGiamGia != null)
			{
				_currentDieuKienGiamGia.Validate();
			}
			//_DieuKienGiamGia.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDieuKienGiamGiaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DieuKienGiamGia"/> instance.
		/// </summary>
		public Entities.DieuKienGiamGia SelectedDieuKienGiamGia
		{
			get {return this._currentDieuKienGiamGia;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDieuKienGiamGiaDataGridView.VirtualMode;}
			set
			{
				this.uxDieuKienGiamGiaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDieuKienGiamGiaDataGridView.AllowUserToAddRows;}
			set {this.uxDieuKienGiamGiaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDieuKienGiamGiaDataGridView.AllowUserToDeleteRows;}
			set {this.uxDieuKienGiamGiaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDieuKienGiamGiaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDieuKienGiamGiaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DieuKienGiamGiaDataGridViewBase"/> class.
		/// </summary>
		public DieuKienGiamGiaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDieuKienGiamGiaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDieuKienGiamGiaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDieuKienGiamGiaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxDieuKienIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDieuKienChungDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxLastUpdateDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxUpdateByDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIsActiveDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDieuKienGiamGiaErrorProvider
			// 
			this.uxDieuKienGiamGiaErrorProvider.ContainerControl = this;
			this.uxDieuKienGiamGiaErrorProvider.DataSource = this.uxDieuKienGiamGiaBindingSource;						
			// 
			// uxDieuKienGiamGiaDataGridView
			// 
			this.uxDieuKienGiamGiaDataGridView.AutoGenerateColumns = false;
			this.uxDieuKienGiamGiaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDieuKienGiamGiaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxDieuKienIdDataGridViewColumn,
		this.uxDieuKienChungDataGridViewColumn,
		this.uxLastUpdateDataGridViewColumn,
		this.uxUpdateByDataGridViewColumn,
		this.uxIsActiveDataGridViewColumn			});
			this.uxDieuKienGiamGiaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDieuKienGiamGiaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDieuKienGiamGiaDataGridView.Name = "uxDieuKienGiamGiaDataGridView";
			this.uxDieuKienGiamGiaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDieuKienGiamGiaDataGridView.TabIndex = 0;	
			this.uxDieuKienGiamGiaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDieuKienGiamGiaDataGridView.EnableHeadersVisualStyles = false;
			this.uxDieuKienGiamGiaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDieuKienGiamGiaDataGridViewDataError);
			this.uxDieuKienGiamGiaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDieuKienGiamGiaDataGridViewCellValueNeeded);
			this.uxDieuKienGiamGiaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDieuKienGiamGiaDataGridViewCellValuePushed);
			
			//
			// uxDieuKienIdDataGridViewColumn
			//
			this.uxDieuKienIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDieuKienIdDataGridViewColumn.DataPropertyName = "DieuKienId";
			this.uxDieuKienIdDataGridViewColumn.HeaderText = "DieuKienId";
			this.uxDieuKienIdDataGridViewColumn.Name = "uxDieuKienIdDataGridViewColumn";
			this.uxDieuKienIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDieuKienIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDieuKienIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxDieuKienChungDataGridViewColumn
			//
			this.uxDieuKienChungDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDieuKienChungDataGridViewColumn.DataPropertyName = "DieuKienChung";
			this.uxDieuKienChungDataGridViewColumn.HeaderText = "DieuKienChung";
			this.uxDieuKienChungDataGridViewColumn.Name = "uxDieuKienChungDataGridViewColumn";
			this.uxDieuKienChungDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDieuKienChungDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDieuKienChungDataGridViewColumn.ReadOnly = false;		
			//
			// uxLastUpdateDataGridViewColumn
			//
			this.uxLastUpdateDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxLastUpdateDataGridViewColumn.DataPropertyName = "LastUpdate";
			this.uxLastUpdateDataGridViewColumn.HeaderText = "LastUpdate";
			this.uxLastUpdateDataGridViewColumn.Name = "uxLastUpdateDataGridViewColumn";
			this.uxLastUpdateDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxLastUpdateDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxLastUpdateDataGridViewColumn.ReadOnly = false;		
			//
			// uxUpdateByDataGridViewColumn
			//
			this.uxUpdateByDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxUpdateByDataGridViewColumn.DataPropertyName = "UpdateBy";
			this.uxUpdateByDataGridViewColumn.HeaderText = "UpdateBy";
			this.uxUpdateByDataGridViewColumn.Name = "uxUpdateByDataGridViewColumn";
			this.uxUpdateByDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxUpdateByDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxUpdateByDataGridViewColumn.ReadOnly = false;		
			//
			// uxIsActiveDataGridViewColumn
			//
			this.uxIsActiveDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIsActiveDataGridViewColumn.DataPropertyName = "IsActive";
			this.uxIsActiveDataGridViewColumn.HeaderText = "IsActive";
			this.uxIsActiveDataGridViewColumn.Name = "uxIsActiveDataGridViewColumn";
			this.uxIsActiveDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIsActiveDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIsActiveDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDieuKienGiamGiaDataGridView);
			this.Name = "DieuKienGiamGiaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDieuKienGiamGiaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DieuKienGiamGiaDataGridViewEventArgs args = new DieuKienGiamGiaDataGridViewEventArgs();
				args.DieuKienGiamGia = _currentDieuKienGiamGia;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DieuKienGiamGiaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DieuKienGiamGia	_DieuKienGiamGia;
	
			/// <summary>
			/// the  Entities.DieuKienGiamGia instance.
			/// </summary>
			public Entities.DieuKienGiamGia DieuKienGiamGia
			{
				get { return _DieuKienGiamGia; }
				set { _DieuKienGiamGia = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDieuKienGiamGiaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDieuKienGiamGiaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDieuKienGiamGiaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDieuKienGiamGiaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDieuKienGiamGiaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxDieuKienIdDataGridViewColumn":
						e.Value = DieuKienGiamGiaList[e.RowIndex].DieuKienId;
						break;
					case "uxDieuKienChungDataGridViewColumn":
						e.Value = DieuKienGiamGiaList[e.RowIndex].DieuKienChung;
						break;
					case "uxLastUpdateDataGridViewColumn":
						e.Value = DieuKienGiamGiaList[e.RowIndex].LastUpdate;
						break;
					case "uxUpdateByDataGridViewColumn":
						e.Value = DieuKienGiamGiaList[e.RowIndex].UpdateBy;
						break;
					case "uxIsActiveDataGridViewColumn":
						e.Value = DieuKienGiamGiaList[e.RowIndex].IsActive;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDieuKienGiamGiaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDieuKienGiamGiaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDieuKienGiamGiaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxDieuKienIdDataGridViewColumn":
						DieuKienGiamGiaList[e.RowIndex].DieuKienId = (System.Guid)e.Value;
						break;
					case "uxDieuKienChungDataGridViewColumn":
						DieuKienGiamGiaList[e.RowIndex].DieuKienChung = (System.String)e.Value;
						break;
					case "uxLastUpdateDataGridViewColumn":
						DieuKienGiamGiaList[e.RowIndex].LastUpdate = (System.DateTime)e.Value;
						break;
					case "uxUpdateByDataGridViewColumn":
						DieuKienGiamGiaList[e.RowIndex].UpdateBy = (System.Int32)e.Value;
						break;
					case "uxIsActiveDataGridViewColumn":
						DieuKienGiamGiaList[e.RowIndex].IsActive = (System.Boolean)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
